<%@taglib prefix="s" uri="/struts-tags"	%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<s:action name="list" namespace="/users" />
<s:action name="list" namespace="/roles" />
<s:action name="list" namespace="/groups" />
<s:action name="listNotGrouped" namespace="/users" />

<article>
	<s:property value="%{usersNotGroupedList}"/>

	<s:if test="hasActionMessages()">
		<s:actionmessage />
	</s:if>
	<s:if test="hasActionErrors()">
		<s:actionerror />
	</s:if>
	
	<h1><s:text name="roGrMan.title"/></h1>
	
	<br/><br/>
	<h1><s:text name="roGrMan.sumTable"/></h1>
	<table id="sumTable" border="1">
		<s:iterator value="%{#request.groupsList}" status="stat2">
			<tr>
				<td><h4><s:text name="general.group"/>_<s:property value="%{#stat2.count}"/>: <s:property value="%{groupName}"/></h4></td>
			</tr>
			
			<s:iterator value="%{usersList}">
				<tr><td>
					<span class="sumTableUsername"><s:property value="%{username}"/></span>
					<span class="sumTableRoles"><s:checkboxlist list="%{#request.rolesList.{roleName}}" value="rolesList.{roleName}" name="strings" disabled="true" theme="simple"/></span>
					<s:if test="%{enabled==false}"><span class="sumTableDisabled"><s:text name="general.disabled"/></span></s:if>
				</td></tr>
			</s:iterator>
		</s:iterator>
		
		
		<tr><td>
			<h4>Not grouped</h4>
		</td></tr>
		<s:iterator value="%{#request.usersNotGroupedList}">
			<tr><td>
				<span class="sumTableUsername"><s:property value="%{username}"/></span>
				<span class="sumTableRoles"><s:checkboxlist list="%{#request.rolesList.{roleName}}" value="rolesList.{roleName}" name="strings" disabled="true" theme="simple"/></span>
				<s:if test="%{enabled==false}"><s:text name="general.disabled"/></s:if>
			</td></tr>
		</s:iterator>
	</table>
		
	<br/><br/>
	<h2><s:text name="general.roles"/></h2>
	<s:iterator value="%{#request.rolesList}">
		<s:form action="edit" namespace="/roles" method="post">
			<s:textfield name="roleEdit.roleName" value="%{roleName}" key="general.roleName" />
			<s:textfield name="roleEdit.notes" value="%{notes}" key="general.notes" />
			<s:checkboxlist list="%{#request.usersList.{username}}" name="strings" value="usersList.{username}" />
			<s:hidden name="page" value="%{page}" />
			<s:hidden name="roleName" value="%{roleName}" />
			<s:submit method="edit" key="general.edit" onclick="return confirm('Confirm?')" />
		</s:form>
		
		<s:url action="delete" namespace="/roles" var="delRol">
			<s:param name="roles_id" value="%{roles_id}" />
			<s:param name="page" value="%{page}" />
		</s:url>
		<span class="padleft">
			<s:a href="%{delRol}" onclick="return confirm('Confirm?')"><s:text name="general.deleteRole"/></s:a>
		</span>
		<br/>
	</s:iterator>
	
	<br/>
	<h3><s:text name="roGrMan.insertRole"/></h3>
	<s:form action="insert" namespace="/roles" method="post">
		<s:textfield name="roleIns.roleName" key="general.role" value=""/>
		<s:textfield name="roleIns.notes" key="general.notes" value=""/>
		<s:checkboxlist list="%{#request.usersList.{username}}" value="" name="strings" />
		<s:hidden name="page" value="%{page}" />
		<s:submit method="insert" key="general.insert" onclick="return confirm('Confirm?')" />
	</s:form>
	
	<br/><br/>
	<h2><s:text name="general.groups"/></h2>
	<s:iterator value="%{#request.groupsList}">
		<s:form action="edit" namespace="/groups" method="post">
			<s:textfield name="groupEdit.groupName" value="%{groupName}" key="general.groupName" />
			<s:checkboxlist list="%{#request.usersList.{username}}" name="strings" value="usersList.{username}" />
			<s:hidden name="page" value="%{page}" />
			<s:hidden name="groupName" value="%{groupName}" />
			<s:submit method="edit" key="general.edit" onclick="return confirm('Confirm?')" />
		</s:form>
		
		<s:url action="delete" namespace="/groups" var="delGr">
			<s:param name="groups_id" value="%{groups_id}" />
			<s:param name="page" value="%{page}" />
		</s:url>
		
		<span class="padleft">
			<s:a href="%{delGr}" onclick="return confirm('Confirm?')"><s:text name="general.deleteGroup"/></s:a>
		</span>
		<br/>
	</s:iterator>
	
	<br/>
	<h3><s:text name="roGrMan.insertGroup"/></h3>
	<s:form action="insert" namespace="/groups" method="get">
		<s:textfield name="groupIns.groupName" key="general.groupName" value=""/>
		<s:checkboxlist list="%{#request.usersList.{username}}" value="" name="strings" />
		<s:hidden name="page" value="%{page}" />
		<s:submit method="insert" key="general.insert" onclick="return confirm('Confirm?')" />
	</s:form>
</article>